<?php
	class PersonnelSettingController extends Zone_Action{
		public function fields(){
			return array(
				basic_salary => array(
					type 		=> 'INT',
					form_label  => 'Lương cơ bản'
				)
			);
		}
				
		
		public function indexAction(){	
			$departments = $this->Model->fetchAll("SELECT 
					`a`.*,
					`b`.`username`,
					`b`.`ID` as `user_id`
				FROM `departments` as `a`
				LEFT JOIN `users` as `b` 
					ON `a`.`created_by_id`=`b`.`ID`
				WHERE `a`.`parent_id`<>0
					  AND `a`.`parent_id` is NOT NULL 
				ORDER BY `ID`");


			$this->set(array(
				side_departments	=> $departments
			));	
			
			if(isPost()){
				$this->removeLayout();
				loadClass('ZData');
				$f = new ZData();
				$f->addField($this->fields());
				$data = $f->getData();				

				if( !is_array( $data ) ){
					return $this->setJson(array(
						alert	=> $data
					));
				}
				
				$this->Model->update('personnels_settings',$data);
				return $this->setJson(array(
					alert => 'Đã cập nhập thành công'
				));				
			}			
			
			$this->set(
				'configs',
				$this->Model->fetchRow("SELECT * FROM `personnels_settings` LIMIT 1")
			);			
		}			
	}
 ?>